/*
 * Queue.cpp
 *
 *  Created on: 2011-04-12
 *      Author: tony
 */

#include "Queue.h"
#include <assert.h>

Queue::Queue(): front(NULL), back(NULL) {
}

Queue::~Queue() {
	while (back != NULL)
		dequeue();
	front = back = NULL;
}

void Queue::enqueue( char d ){
	if (back == NULL)
		front = back = new Node( d, NULL, NULL );
	else{
		back = new Node( d, back, NULL );
		back->getNext()->setPrev( back );
	}
}

char Queue::dequeue(){
	assert( front != NULL );
	Node* result = front;

	if (front == back) {
		front = back = NULL;
	} else {
		front = front->getPrev();
		front->setNext( NULL );
	}
	char d = result->get();
	delete result;
	return d;
}

bool Queue::is_empty(){
	return (front == NULL);
}
